<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/maa.tld" prefix="m" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:setLocale value="${language}"/>
<fmt:bundle basename="messages" prefix="courses.">
<html>
<head>
    <title><fmt:message key="title"/></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="${pageContext.servletContext.contextPath}/static/bootstrap/css/bootstrap.css">
    <link href="${pageContext.request.contextPath}/css/courses.css" rel="stylesheet">
    <link rel="shortcut icon" href="${pageContext.servletContext.contextPath}/static/yin.ico">
    <script type="text/javascript"
            src="${pageContext.servletContext.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
    <style type="text/css"></style>
</head>

<body>
<div class="navbar-wrapper">
    <div class="container-fluid">
        <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="/maa/do?action=main"> <img
                            src="${pageContext.servletContext.contextPath}/static/ics.png"/>Silver Dragon</a>
                </div>
                <div class="navbar-collapse collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <c:choose>
                            <c:when test="${not empty user and user.role == 'CLIENT'}">
                                <li><a><strong><fmt:message key="greet"/> ${user.name} ${user.surname}!</strong></a>
                                </li>
                                <li><a href="/maa/do?action=account"><fmt:message key="account"/></a></li>
                                <li><a href="/maa/do?action=main"><fmt:message key="main"/></a></li>
                                <li>
                                    <form action="/maa/do" method="post">
                                        <input type="hidden" name="action" value="logout">
                                        <input class="btn btn-default" type="submit"
                                               value="<fmt:message key="logout"/>"/>
                                    </form>
                                </li>
                                <m:language/>
                            </c:when>
                            <c:when test="${not empty user and user.role == 'MENTOR'}">
                                <li><a><strong><fmt:message key="greet"/> ${user.name} ${user.surname}!</strong></a>
                                </li>
                                <li><a href="/maa/do?action=account"><fmt:message key="account"/></a></li>
                                <li><a href="/maa/do?action=main"><fmt:message key="main"/></a></li>
                                <li>
                                    <form action="/maa/do" method="post">
                                        <input type="hidden" name="action" value="logout">
                                        <input class="btn btn-default" type="submit"
                                               value="<fmt:message key="logout"/>"/>
                                    </form>
                                </li>
                                <m:language/>
                            </c:when>
                            <c:when test="${not empty user and user.role == 'ADMIN'}">
                                <li><a><strong><fmt:message key="greet"/> ${user.name} ${user.surname}!</strong></a>
                                </li>
                                <li><a href="/maa/do?action=admin-cabinet"><fmt:message key="cabinet"/></a></li>
                                <li><a href="/maa/do?action=main"><fmt:message key="main"/></a></li>
                                <li>
                                    <form action="/maa/do" method="post">
                                        <input type="hidden" name="action" value="logout">
                                        <input class="btn btn-default" type="submit"
                                               value="<fmt:message key="logout"/>"/>
                                    </form>
                                </li>
                                <m:language/>
                            </c:when>
                            <c:otherwise>
                                <li><a href="/maa/do?action=login-form"><fmt:message key="login"/></a></li>
                                <li><a href="/maa/do?action=registration-form"><fmt:message key="register"/></a></li>
                                <li><a href="/maa/do?action=main"><fmt:message key="main"/></a></li>
                                <m:language/>
                            </c:otherwise>
                        </c:choose>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container">
    <div class="row row-offcanvas row-offcanvas-right">
        <div class="col-xs-12 col-sm-9">
            <p class="pull-right visible-xs">
                <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
            </p>
            <div class="jumbotron">
                <c:if test="${not empty user}">
                    <h1><fmt:message key="dear"/> ${user.name},</h1>
                </c:if>
                <c:if test="${ empty user}">
                    <h1><fmt:message key="dearv"/></h1>
                </c:if>

                <p><fmt:message key="mes"/></p>

                <c:if test="${not empty already_subscribed}">
                    <p><%=request.getAttribute("already_subscribed")%>
                    </p>
                </c:if>
            </div>
            <div class="row">
                <c:forEach items="${courses}" var="course">
                    <div class="col-6 col-sm-6 col-lg-4">
                        <h2>${course.courseName}</h2>

                        <p>${course.courseDescription}</p>

                        <p><fmt:message key="price"/> ${course.courseMonthlyPrice}</p>

                        <p><fmt:message key="mentor"/> ${course.mentor.name} ${course.mentor.surname}</p>
                        <c:if test="${not empty user and user.role == 'CLIENT'}">
                            <form action="/maa/do" method="post">
                                <input type="hidden" name="action" value="subscribe"/>
                                <input type="hidden" name="course-uuid" value=${course.uuid}/>
                                <input class="btn" type="submit" value="<fmt:message key="sub"/>"/></form>
                        </c:if>
                        <c:if test="${not empty user and user.role == 'ADMIN'}">
                            <form action="/maa/do" method="post">
                                <input type="hidden" name="action" value="course-update-page"/>
                                <input type="hidden" name="uuid" value=${course.uuid}/>
                                <input class="btn" type="submit" value="<fmt:message key="update"/>"/></form>
                        </c:if>
                    </div>
                </c:forEach>
            </div>
        </div>
        <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
            <div class="list-group">
                <a href="/maa/do?action=main" class="list-group-item"><fmt:message key="main"/></a>
                <a href="/maa/do?action=courses" class="list-group-item"><fmt:message key="courses"/></a>
                <a href="/maa/do?action=mentors" class="list-group-item"><fmt:message key="mentors"/></a>
                <c:if test="${not empty user and user.role == 'ADMIN'}">
                    <a href="/maa/do?action=groups" class="list-group-item"><fmt:message key="groups"/></a>
                </c:if>
            </div>
        </div>
    </div>
</div>

<script src="./Off Canvas Template for Bootstrap_files/jquery.min.js"></script>
<script src="./Off Canvas Template for Bootstrap_files/bootstrap.min.js"></script>
<script src="./Off Canvas Template for Bootstrap_files/offcanvas.js"></script>


</body>
</html>
</fmt:bundle>